package com.accenture.adf.newcodington.module16.sample.advanced;

import org.junit.Test;


import junit.framework.TestCase;

/**
 * Testcase for demonstrate unit tests for MyCalculatorTryIt
 */
public class TestMyCalculatorTryIt extends TestCase {

	MyCalculatorTryIt calculator;

	protected void setUp() throws Exception {
		super.setUp();
		calculator = new MyCalculatorTryIt();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	@Test
	/**
	 * Positive testcase for addNumbers method
	 */
	public void testAddNumbers_Positive() {
		int num1 = 23;
		int num2 = 34;
		try {
			assertEquals(57, calculator.addNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			fail("No exception should be thrown");
		}
	}

	@Test
	/**
	 * Positive testcase for subtractNumbers method
	 */
	public void testSubtractNumbers_Positive() {
		int num1 = 23;
		int num2 = 12;
		try {
			assertEquals(11, calculator.subtractNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			fail("No exception should be thrown");
		}
	}

	@Test
	/**
	 * Positive testcase for MultiplyNumbers method
	 */
	public void testMultiplyNumbers_Positive() {
		int num1 = 3;
		int num2 = 2;
		try {
			assertEquals(6.0, calculator.multiplyNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			fail("No exception should be thrown");
		}
	}

	@Test
	/**
	 * Positive testcase for DivideNumbers method
	 */
	public void testDivideNumbers_Positive() {
		int num1 = 30;
		int num2 = 2;
		try {
			assertEquals(15.0, calculator.divideNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			fail("No exception should be thrown");
		}
	}

	@Test
	/**
	 * Negative testcase for checking result exceeding 8 digits
	 */
	public void testAddNumbers_Negative() {
		int num1 = 99999999;
		int num2 = 1;
		try {
			assertEquals(100000000, calculator.addNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking result exceeding 8 digits
	 */
	public void testSubtractNumbers_Negative() {
		int num1 = -99999999;
		int num2 = 1;
		try {
			assertEquals(-1000000000, calculator.subtractNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking result exceeding 8 digits
	 */
	public void testMultiplyNumbers_Negative() {
		double num1 = 84938;
		double num2 = 87865;
		try {
			assertEquals(84938.0*87865.0, calculator.multiplyNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}


	@Test
	/**
	 * Negative testcase for checking output exceeding 8 digits
	 */
	public void testDivideNumbers_Negative() {
		double num1 = 78348;
		double num2 = 0.0003;
		try {
			assertEquals(78348/0.0003,
					calculator.divideNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 1st operand exceeding 8 digits
	 */
	public void testAddNumbers_1stOperandTooLarge_Negative() {
		int num1 = 999999999;
		int num2 = 1;
		try {
			assertEquals(999999999 + 1, calculator.addNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 2nd operand exceeding 8 digits
	 */
	public void testAddNumbers_2ndOperandTooLarge_Negative() {
		int num1 = 1;
		int num2 = 999999999;
		try {
			assertEquals(999999999 + 1, calculator.addNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 1st operand exceeding 8 digits
	 */
	public void testSubtractNumbers_1stOperandTooLarge_Negative() {
		int num1 = -999999999;
		int num2 = 1;
		try {
			assertEquals(-999999999 - 1, calculator.subtractNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 2nd operand exceeding 8 digits
	 */
	public void testSubtractNumbers_2ndOperandTooLarge_Negative() {
		int num1 = 1;
		int num2 = -999999999;
		try {
			assertEquals(1 + 999999999, calculator.subtractNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 1st operand exceeding 8 digits
	 */
	public void testMultiplyNumbers_1stOperandTooLarge_Negative() {
		double num1 = 849382987.0;
		double num2 = 878653.0;
		try {
			assertEquals(849382987.0 * 878653.0,
					calculator.multiplyNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	/**
	 * Negative testcase for checking 2nd operand exceeding 10 digits
	 */
	public void testMultiplyNumbers_2ndOperandTooLarge_Negative() {
		double num1 = 878653.0;
		double num2 = 849382987.0;
		try {
			assertEquals(849382987.0 * 878653.0,
					calculator.multiplyNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 1st operand exceeding 8 digits
	 */
	public void testDivideNumbers_1stOperandTooLarge_Negative() {
		double num1 = 999999999.0;
		double num2 = 5.0;
		try {
			assertEquals(999999999.0 / 5.0,
					calculator.divideNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Negative testcase for checking 2nd operand exceeding 8 digits
	 */
	public void testDivideNumbers_2ndOperandTooLarge_Negative() {
		double num1 = 5.0;
		double num2 = 999999999.0;
		try {
			assertEquals(5.0 / 999999999.0,
					calculator.divideNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

	@Test
	/**
	 * Exception testcase for checking divide by Zero value
	 */
	public void testDivideNumbers_Exception() {
		int num1 = 20;
		int num2 = 0;
		try {
			assertEquals(5, calculator.divideNumbers(num1, num2));
		} catch (ArithmeticException ex) {
			assertEquals("-Error-", ex.getMessage());
		}
	}

}
